package test;

import java.sql.*;

public class 默写 {
    public void ByName1(String ename) throws ClassNotFoundException, SQLException{
        //加载驱动
        Class.forName("oracle.jdbc.driver.OracledDriver");
        //创建连接
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//127.0.0.1:1521/orc1","scott","123");
        //构造语句
        //？代表占位符
        String sql = "select*from emp where ename = ?";
        PreparedStatement stat = conn.prepareStatement(sql);
        //设置参数，代替对应的？的占位符
        stat.setString(1,ename);
        //执行语句
        ResultSet rs = stat.executeQuery();
        //对结果集进行遍历
        while (rs.next()){
            //获取第一个字段的值empno
            int empno = rs.getInt(1);
            //通过字段名获取字段值
            String eName = rs.getString("ENAME");
            Date hiredate = rs.getDate("HIREDATE");
            System.out.printf("%10d  %20s  %s  \n",empno,eName,hiredate);
        }
        //关闭资源
       rs.close();
       stat.close();
       conn.close();

    }



}
